/**
 * @param {string} haystack
 * @param {string} needle
 * @return {number}
 */
var strStr = function(haystack, needle) {
  if(needle.length === 0)
    return 0;
  if(needle.length > haystack.length)
    return -1;
  for(let i = 0; i < haystack.length; i++) {
    for(let j = 0; j < needle.length; j++) {
      if(haystack[i + j] != needle[j]) {
        break;
      }
      if(j == needle.length - 1)
        return i;
    }
    if(needle.length > haystack.length - i)
      return -1;
  }
  return -1;
};
let haystack = "hello", needle = "ll";
console.log(strStr(haystack, needle));
haystack = "aaaaa", needle = "bba";
console.log(strStr(haystack, needle));
haystack = "", needle = "";
console.log(strStr(haystack, needle));
haystack = "aaa", needle = "aaaa";
console.log(strStr(haystack, needle));
haystack = "mississippi", needle = "a";
console.log(strStr(haystack, needle));
haystack = "mississippi", needle = "mississippi";
console.log(strStr(haystack, needle));
